EMBEDDED_KERNEL=no

obj := $(shell pwd)
include $(obj)/../../../linux_config.mak

ifeq ($(KERN_26), y)

ifneq ($(KERNELRELEASE),)
fcap_drv-objs := i2c.o fcap_misc.o fcap.o fcap_ctrl.o
obj-m += fcap_drv.o
obj-m := $(sort $(obj-m))

else

PWD := $(shell pwd)
all modules:
	$(MAKE) -C $(LINUX_SRC) M=$(PWD) modules
	#cp fcap_drv.ko /usr/src/arm-linux-2.6/target/packages/ffmpeg-0.4.8/ffmpeg
	cp fcap_drv.ko /tmp

clean:
	$(MAKE) -C $(LINUX_SRC) M=$(PWD) clean
endif

ifeq ($(CONFIG_PLATFORM_FIC8120),y)
    CFLAGS += -DFIC8120
endif

ifeq ($(CONFIG_FIE8150_PLATFORM),y)
    CFLAGS += -DFIE8150
endif

else

CROSS = arm-linux-

ifeq ($(CROSS),arm-linux-)
	INCLUDE = /usr/src/arm-linux/arm-linux-2.4.19/include
	CFLAGS = -g -O3 -march=armv4 -mtune=arm9tdmi $(OPTFLAGS) -D__KERNEL__ -I$(INCLUDE) -I. -Wall -Wstrict-prototypes  -fno-strict-aliasing -pipe -mapcs-32 -mshort-load-bytes -msoft-float 
else
	INCLUDE = /usr/src/linux-2.4.19/include
	CFLAGS =  -D__KERNEL__ -I$(INCLUDE) -I. -Wall -Wstrict-prototypes  -fno-strict-aliasing -pipe
endif


ifeq ($(EMBEDDED_KERNEL),yes)
    CFLAGS+= -gdwarf-2
else
    CFLAGS+= -DMODULE
endif


ifeq ($(CONFIG_FIC8120_PLATFORM),y)
	CFLAGS += -DFIC8120
endif

ifeq ($(CONFIG_FIE8150_PLATFORM),y)
	CFLAGS += -DFIE8150
endif

CC = $(CROSS)gcc
LINK = $(CROSS)ld
EXEC = fcap_drv.o

LDFLAGS = -r -o $(EXEC)
OBJECTS =  i2c.o fcap_misc.o fcap.o fcap_ctrl.o

all: $(OBJECTS)
	$(LINK) $(LDFLAGS) $(OBJECTS)
	cp $(EXEC) /tmp
	#cp $(EXEC) /usr/src/arm-linux/arm-linux-2.4.19/drivers/video

%.o: %.c
	$(CC)  $(CFLAGS) -c -o $@ $<

insmod:
	insmod $(EXEC) -f

rmmod:
	rmmod fcap_drv

clean:
	rm -rf *.o

Makefile.depend depend:
	arm-linux-gcc -DLINUX -MM -MG *.c > Makefile.depend

include Makefile.depend

endif
